import 'package:flutter/material.dart';

// 自定义缓存组件
class MyKeepAliveWrapper extends StatefulWidget {
  const MyKeepAliveWrapper(
      {Key? key, required this.child, this.keepAlive = true})
      : super(key: key);

  final Widget child;
  final bool keepAlive;

  @override
  _MyKeepAliveWrapperState createState() => _MyKeepAliveWrapperState();
}

class _MyKeepAliveWrapperState extends State<MyKeepAliveWrapper>
    with AutomaticKeepAliveClientMixin {
  @override
  Widget build(BuildContext context) {
    super.build(context);
    return widget.child;
  }

  @override
  bool get wantKeepAlive => widget.keepAlive;
}
